package com.simons.common.utils;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

public class PoolUtil {

//	public static final GenericObjectPoolConfig poolConfig = getGenericObjectPoolConfig();
	
	public static GenericObjectPoolConfig getGenericObjectPoolConfig(){
		GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
		poolConfig.setMaxTotal(20); //允许创建资源的最大数量，默认值 8，-1 代表无数量限制（int类型）
	    poolConfig.setBlockWhenExhausted(true);
	    poolConfig.setMaxWaitMillis(-1);
	    poolConfig.setTestOnBorrow(false);
	    poolConfig.setTestOnCreate(false);
	    poolConfig.setLifo(true);
	    poolConfig.setFairness(false);
	    poolConfig.setTimeBetweenEvictionRunsMillis(30*1000L);//十分钟执行一次资源回收
//	    poolConfig.setEvictionPolicyClassName(null);
	    poolConfig.setMinEvictableIdleTimeMillis(30*1000L);//资源最小空闲时间，
	    poolConfig.setSoftMinEvictableIdleTimeMillis(30*1000L);
	    poolConfig.setMinIdle(0);
	    poolConfig.setMaxIdle(8);
	    poolConfig.setTestWhileIdle(true);
	    poolConfig.setTestOnReturn(true);
	    poolConfig.setNumTestsPerEvictionRun(8);
	    
	    return poolConfig;
	}
	
}
